import { ref } from 'vue'
import { SpareDisable, SpareDelete } from '@/api/goodsInfo'
import { EnableOrDisableOrDeleteRes } from './types'

const useSpare = () => {
  const spareMultipleDisableLoading = ref(false)
  const spareMultipleDisable = async (spareIds: Array<string>) => {
    spareMultipleDisableLoading.value = true
    const res = await SpareDisable(spareIds, true)
    spareMultipleDisableLoading.value = false
    return res.data as EnableOrDisableOrDeleteRes
  }

  const spareMultipleEnableLoading = ref(false)
  const spareMultipleEnable = async (spareIds: Array<string>) => {
    spareMultipleEnableLoading.value = true
    const res = await SpareDisable(spareIds, false)
    spareMultipleEnableLoading.value = true
    return res.data as EnableOrDisableOrDeleteRes
  }

  const spareMultipleDeleteLoading = ref(false)
  const spareMultipleDelete = async (spareIds: Array<string>) => {
    spareMultipleDeleteLoading.value = true
    const res = await SpareDelete(spareIds)
    spareMultipleDeleteLoading.value = false
    return res.data as EnableOrDisableOrDeleteRes
  }

  return {
    spareMultipleDeleteLoading,
    spareMultipleEnableLoading,
    spareMultipleDisableLoading,
    spareMultipleDelete,
    spareMultipleEnable,
    spareMultipleDisable,
  }
}

export default useSpare
